/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
import { CategoryType, CompanyType, JobType } from "@/types/pro";
import request from "@/utils/request";
import { h5, ios, java,other } from "@/mock/joblist";

export const categoryPost = (category: CategoryType) => {
  return request.post("classes/ReactCategory", category);
};

export const categoryGet = () => {
  // return request.get(`classes/ReactCategory?where={"level":{"$lt":3}}`);
  return request.get(`classes/ReactCategory`);
};

//更新类目
export const categoryPut = (objectId: string, category: CategoryType) => {
  return request.put(`classes/ReactCategory/${objectId}`, category);
};

//企业入驻
export const companyPost = (company: CompanyType) => {
  return request.post("users", {
    username: company.name,
    password: "123",
    ...company,
    type: 1,
  });
};

//企业设置
export const companyPut = (
  companyId: string,
  company: CompanyType,
  session: string
) => {
  return request.put(`users/${companyId}`, company, {
    headers: {
      "X-LC-Session": session,
    },
  });
};

// 企业列表
export const companyGet = () => {
  return request.get(`users?where={"type":1}`);
};

// 批量录入岗位
export const jobBatch = (job: JobType) => {
  let mock = { h5, ios, java,other };
  let list = mock[job.mockname].zpData.jobList;
  console.log(list);
  let requests = list.map((item) => {
    return {
      method: "POST",
      path: "/1.1/classes/ReactJob",
      body: {
        ...item,
        ...job,
      },
    };
  });

  return request.post("batch", { requests });
};

//加载岗位
interface JobParamsType {
  current?: number;
  pageSize?: number;
  createAt?: Array<string>;
  jobName?: string;
  jobDegree?: string;
}
interface JobQueryType {
  jobName?: { $regex: string; $options: "i" };
  jobDegree?: string;
}
export const jobGet = (companyId: string, params: JobParamsType) => {
  let query: JobQueryType = {
    jobDegree: params.jobDegree,
  };
  if (params.jobName) {
    query.jobName = { $regex: params.jobName, $options: "i" };
  }
  return request.get(`classes/ReactJob`, {
    params: {
      where: {
        companyId,
        ...query,
      },
    },
  });
};
